package com.blb.springbean;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;

public class MyBean implements BeanNameAware, InitializingBean, DisposableBean {

    public MyBean(){
        System.out.println("1）实例化MyBean");
    }

    private String name;

    public String getName() {
        return name;
    }

    @Value("${mybean.name}")
    public void setName(String name) {
        this.name = name;
        System.out.println("2）对象的属性赋值");
    }


    @Override
    public void setBeanName(String s) {
        System.out.println("3）执行Aware接口方法 " + s);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("5) 如果实现InitializingBean执行afterPropertiesSet方法");
    }

    public void initMyBean(){
        System.out.println("6）如果配置过init-method执行该方法");
    }

    public void destoryMyBean(){
        System.out.println("9）如果配置过destory-method执行该方法");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("8）如果实现DisposableBean执行destory方法");
    }
}
